#!/bin/bash

# 导入台湾省、香港特别行政区、澳门特别行政区数据脚本
echo "开始导入台湾省、香港特别行政区、澳门特别行政区数据..."

# 逐个导入，跳过TRUNCATE语句
echo "正在导入台湾省..."
docker exec mysql-5.7 bash -c "grep -v 'TRUNCATE TABLE' /tmp/province_sqls/province_71_台湾省.sql > /tmp/temp_province_71_台湾省.sql"
docker exec -i mysql-5.7 mysql -uroot -p'abc#$123' smart_community < <(docker exec mysql-5.7 cat /tmp/temp_province_71_台湾省.sql)
docker exec mysql-5.7 rm -f /tmp/temp_province_71_台湾省.sql

echo "正在导入香港特别行政区..."
docker exec mysql-5.7 bash -c "grep -v 'TRUNCATE TABLE' /tmp/province_sqls/province_81_香港特别行政区.sql > /tmp/temp_province_81_香港特别行政区.sql"
docker exec -i mysql-5.7 mysql -uroot -p'abc#$123' smart_community < <(docker exec mysql-5.7 cat /tmp/temp_province_81_香港特别行政区.sql)
docker exec mysql-5.7 rm -f /tmp/temp_province_81_香港特别行政区.sql

echo "正在导入澳门特别行政区..."
docker exec mysql-5.7 bash -c "grep -v 'TRUNCATE TABLE' /tmp/province_sqls/province_82_澳门特别行政区.sql > /tmp/temp_province_82_澳门特别行政区.sql"
docker exec -i mysql-5.7 mysql -uroot -p'abc#$123' smart_community < <(docker exec mysql-5.7 cat /tmp/temp_province_82_澳门特别行政区.sql)
docker exec mysql-5.7 rm -f /tmp/temp_province_82_澳门特别行政区.sql

# 显示导入结果统计
echo "导入完成，统计结果："
docker exec mysql-5.7 mysql -uroot -p'abc#$123' smart_community -e "
SELECT 
    region_type,
    COUNT(*) as count,
    CASE region_type 
        WHEN 1 THEN '省级'
        WHEN 2 THEN '市级' 
        WHEN 3 THEN '区县级'
        WHEN 4 THEN '街道级'
        WHEN 5 THEN '社区级'
        ELSE '其他'
    END as type_name
FROM sc_region 
GROUP BY region_type 
ORDER BY region_type;
"

echo "台湾省、香港特别行政区、澳门特别行政区数据导入完成！" 